package com.ruoyi.web.controller.workflow;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.workflow.domain.Statement;
import org.simpleframework.xml.Path;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.workflow.domain.AppointmentInfo;
import com.ruoyi.workflow.service.IAppointmentInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author xiaodu
 * @date 2023-07-21
 */
@RestController
@RequestMapping("/workflow/appointmentInfo")
public class AppointmentInfoController extends BaseController
{
    @Autowired
    private IAppointmentInfoService appointmentInfoService;

    /**
     * 已到店
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:arrival')")
    @PutMapping("arrival/{id}")
    public AjaxResult arrival(@PathVariable Long id){
        appointmentInfoService.arrival(id);
        return AjaxResult.success("操作成功");
    }

    /**
     * 取消预约
     * @param id 预约信息ID
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:cancel')")
    @GetMapping("cancel/{id}")
    public AjaxResult cancel(@PathVariable Long id){
        appointmentInfoService.cancel(id);
        return AjaxResult.success("操作成功");
    }

    /**
     * 生成结算单
     * @param id 预约信息的ID
     * return  返回生成结算单的ID
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:generateStatement')")
    @GetMapping("generateStatement/{id}")
    public AjaxResult generateStatement(@PathVariable Long id){
        appointmentInfoService.generateStatement(id);
        return AjaxResult.success("成功生成结算单");
    }


    /**
     * 查询预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppointmentInfo appointmentInfo)
    {
        startPage();
        List<AppointmentInfo> list = appointmentInfoService.selectAppointmentInfoList(appointmentInfo);
        return getDataTable(list);
    }

    /**
     * 导出预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:export')")
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppointmentInfo appointmentInfo)
    {
        List<AppointmentInfo> list = appointmentInfoService.selectAppointmentInfoList(appointmentInfo);
        ExcelUtil<AppointmentInfo> util = new ExcelUtil<AppointmentInfo>(AppointmentInfo.class);
        util.exportExcel(response, list, "预约信息数据");
    }

    /**
     * 获取预约信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appointmentInfoService.selectAppointmentInfoById(id));
    }

    /**
     * 新增预约信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:add')")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppointmentInfo appointmentInfo)
    {
        return toAjax(appointmentInfoService.insertAppointmentInfo(appointmentInfo));
    }

    /**
     * 修改预约信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:edit')")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppointmentInfo appointmentInfo)
    {
        return toAjax(appointmentInfoService.updateAppointmentInfo(appointmentInfo));
    }

    /**
     * 删除预约信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:appointmentInfo:remove')")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appointmentInfoService.deleteAppointmentInfoByIds(ids));
    }
}
